package com.demo.nfcdemo.v;

import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.demo.nfcdemo.R;
import com.demo.nfcdemo.simulate.CardSimulateCallback;

/**
 * @author ljb
 * @des
 * @date 2020/5/23
 */
public class CActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_c);

    }

    public void onClick(View v) {
        if (R.id.bt_simulate_read == v.getId()) {
            showDialog("读卡器模式...");
            NfcAdapter.getDefaultAdapter(this).enableReaderMode(this, new CardSimulateCallback(this), NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK | NfcAdapter.FLAG_READER_NFC_A, null);
        }

    }

    private AlertDialog alertDialog;

    public void showDialog(String msg) {
        if (alertDialog == null) {
            alertDialog = new AlertDialog.Builder(this)
                    .create();
        }
        alertDialog.setMessage(msg);
        alertDialog.show();
    }
}
